package temp.casia.isiteam.zrb.hbase.client;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.HTablePool;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.log4j.Logger;

import temp.casia.isiteam.zrb.hbase.client.bean.HBProjectAdvantage;
import temp.casia.isiteam.zrb.hbase.client.bean.HBProjectAttachment;
import temp.casia.isiteam.zrb.hbase.client.bean.HBProjectEconomic;
import temp.casia.isiteam.zrb.hbase.client.bean.HBProjectInfo;
import temp.casia.isiteam.zrb.hbase.client.bean.HBProjectMarket;
import temp.casia.isiteam.zrb.hbase.client.bean.HBProjectMedia;
import temp.casia.isiteam.zrb.hbase.client.bean.HbaseStatus;
import temp.casia.isiteam.zrb.hbase.client.bean.ProjectQueryTerm;
import temp.casia.isiteam.zrb.hbase.client.bean.table.HbaseTableProjectAdvantage;
import temp.casia.isiteam.zrb.hbase.client.bean.table.HbaseTableProjectAttachment;
import temp.casia.isiteam.zrb.hbase.client.bean.table.HbaseTableProjectEconomic;
import temp.casia.isiteam.zrb.hbase.client.bean.table.HbaseTableProjectInfo;
import temp.casia.isiteam.zrb.hbase.client.bean.table.HbaseTableProjectMarket;
import temp.casia.isiteam.zrb.hbase.client.bean.table.HbaseTableProjectMedia;
import temp.casia.isiteam.zrb.hbase.client.util.Commons;
import temp.casia.isiteam.zrb.hbase.client.util.ConnectionManager;
import temp.casia.isiteam.zrb.hbase.client.util.MD5Util;

/**
 * 项目信息操作类<br>
 * 提供HBase中项目相关表的查询、写入
 * @author 彭鑫
 * @createDate 2015年6月29日
 */
@Deprecated
public class ProjectHbaseClient {
	protected Configuration config;
	private Logger logger = Logger.getLogger(ProjectHbaseClient.class);
	/**
	 * 表名
	 */
	protected Map<String, TableName> tableNameMap;
	protected String quorum;
	protected Integer currentClientNum = 0;
	private Timer timer;
	private int retryTimes = 0;
	
	/**
	 * 使用默认的master地址
	 */
	public ProjectHbaseClient(){
		this.quorum = Commons.quorum;
		this.initConfig();
	}
	


	
	/**
	 * 指定master地址
	 * @param quorum
	 */
	public ProjectHbaseClient(String quorum){
		this.quorum = quorum;
		this.initConfig();
	}
	
	protected void initConfig() {
		Connection conn = null;
		try {
			config = HBaseConfiguration.create();
			config.set("hbase.zookeeper.quorum", this.quorum);
			config.set("hbase.client.retries.number", "3");
			config.set("zookeeper.recovery.retry", "3");
			
			conn = ConnectionManager.getConn(config);
			Admin admin = conn.getAdmin();
			TableName[] tableAry = admin.listTableNames("project_.*");
			this.tableNameMap = new HashMap<String, TableName>();
			for (TableName tableName : tableAry) {
				this.tableNameMap.put(tableName.getNameAsString(), tableName);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			this.closeConn(conn);
		}
	}

	protected Connection initConn() {
		Connection conn = ConnectionManager.getConn(config);
		return conn;
	}
	
	/**
	 * 查询项目所有信息
	 * @param provincePostcode
	 * @param cityPostcode
	 * @param countyPostcode
	 * @param projectID
	 * @return
	 */
	public HBProjectInfo getProjectInfoAll(String provincePostcode, String cityPostcode, String countyPostcode, int projectID){
		this.retryTimes = 0;
		HBProjectInfo project = this.getProjectInfoBasic(provincePostcode, cityPostcode, countyPostcode, projectID);
		if(project != null){
			project.setAdvantage(this.getProjectAdvantage(provincePostcode, cityPostcode, countyPostcode, projectID));
			project.setMarket(this.getProjectMarket(provincePostcode, cityPostcode, countyPostcode, projectID));
			project.setAttList(this.getProjectAttach(provincePostcode, cityPostcode, countyPostcode, projectID));
			project.setEconomic(this.getProjectEconomic(provincePostcode, cityPostcode, countyPostcode, projectID));
			project.setMediaList(this.getProjectMedia(provincePostcode, cityPostcode, countyPostcode, projectID));
		}
		return project;
	}
	
	/**
	 * 
	 * 批量查询项目
	 * @param termList
	 * @return
	 */
	public List<HBProjectInfo> getProjectInfoBasic(List<ProjectQueryTerm> termList){
		List<HBProjectInfo> list = new ArrayList<HBProjectInfo>();
		Table table = null;
		Connection conn = null;
		try {
			conn = this.initConn();
			table = conn.getTable(this.tableNameMap.get(HbaseTableProjectInfo.TABLE_NAME));
			List<Get> getList = new ArrayList<Get>();
			for(ProjectQueryTerm term: termList){
				if(term.getProvincePostcode() == null || term.getProvincePostcode().length() == 0 || term.getMysqlID() <= 0){
					this.logger.warn("postcode of province is null! or mysqlid is 0!");
					continue;
				}
				if(term.getCityPostcode() == null || term.getCityPostcode().length() == 0){
					term.setCityPostcode("0");
				}
				if(term.getCountyPostcode() == null || term.getCountyPostcode().length() == 0){
					term.setCountyPostcode("0");
				}
				String rowKey = term.getProvincePostcode() + "_" + term.getCityPostcode() + "_" + term.getCountyPostcode() + "_" + term.getMysqlID();
				Get get = new Get(Bytes.toBytes(rowKey));
				getList.add(get);
			}
			Result[] results = table.get(getList);
			for(Result result: results){
				HBProjectInfo project = this.getProjectBean(result);
				if(project != null){
					list.add(project);
				}
			}
		} catch (Exception e) {
			this.logger.error("Exception! ", e);
			if(++this.retryTimes <= 5){
				try {
					Thread.sleep(2000);
				} catch (Exception e1) {}
				list = this.getProjectInfoBasic(termList);
			}
			e.printStackTrace();
		} finally {
			this.closeConn(table, conn);
		}
		return list;
	}
	
	/**
	 * 查询项目基本信息
	 * @param provincePostcode
	 * @param cityPostcode
	 * @param countyPostcode
	 * @param projectID
	 * @return
	 */
	public HBProjectInfo getProjectInfoBasic(String provincePostcode, String cityPostcode, String countyPostcode, int projectID){
		HBProjectInfo project = null;
		Table table = null;
		Connection conn = null;
		try {
			conn = this.initConn();
			table = conn.getTable(this.tableNameMap.get(HbaseTableProjectInfo.TABLE_NAME));
			if(cityPostcode == null || cityPostcode.length() == 0){
				cityPostcode = "0";
			}
			if(countyPostcode == null || countyPostcode.length() == 0){
				countyPostcode = "0";
			}
			String rowKey = provincePostcode + "_" + cityPostcode + "_" + countyPostcode + "_" + projectID;
			Get get = new Get(Bytes.toBytes(rowKey));
			Result result = table.get(get);
			if (result != null) {
				project = this.getProjectBean(result);
			}
			this.retryTimes = 0;
		} catch (Exception e) {
			this.logger.error("Exception! key: " + provincePostcode + "_" + cityPostcode + "_" + countyPostcode + "_" + projectID, e);
			if(++this.retryTimes <= 5){
				try {
					Thread.sleep(2000);
				} catch (Exception e1) {}
				project = this.getProjectInfoBasic(provincePostcode, cityPostcode, countyPostcode, projectID);
			}
		} finally {
			this.closeConn(table, conn);
		}
		return project;
	}
	
	private HBProjectInfo getProjectBean(Result result){
		if(result.isEmpty()){
			return null;
		}
		HBProjectInfo project = new HBProjectInfo();
		String rowKey = Bytes.toString(result.getRow());
		String[] infos = rowKey.split("_");
		project.setProvincePostcode(infos[0]);
		if(infos[1].equals("0")){
			project.setCityPostcode(null);
		} else{
			project.setCityPostcode(infos[1]);
		}
		if(infos[2].equals("0")){
			project.setCountyPostcode(null);
		} else{
			project.setCountyPostcode(infos[2]);
		}
		project.setMysqlID(Integer.parseInt(infos[3]));
		
		project.setType(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_type));
		project.setName(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_name));
		project.setIsCase(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_isCase));
		project.setCity(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_city));
		project.setCityKey(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_cityKey));
		project.setHotValue(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_hotValue));
		project.setIsValidate(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_isValidate));
		project.setStatus(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_status));
		project.setIntro(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_intro));
		project.setInvestment(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_investment));
		project.setTrade(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_trade));
		project.setDeposit(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_deposit));
		project.setReserve(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_reserve));
		project.setPayment(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_payment));
		project.setTradeDate(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_tradeDate));
		project.setLocation(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_location));
		project.setGeoCoor(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_geoCoor));
		project.setRestricted(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_restricted));
		project.setPolicy(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_policy));
		project.setKeywords(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_keywords));
		project.setBackground(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_background));
		project.setAssetType(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_assetType));
		project.setAssetIndex(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_assetIndex));
		project.setPurpose(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_purpose));
		project.setPlotRatio(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_plotRatio));
		project.setYwhjf(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_ywhjf));
		project.setBuilDensity(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_builDensity));
		project.setGreeningRate(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_greeningRate));
		project.setMaxHeight(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_maxHeight));
		project.setArea(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_area));
		project.setUnitPrice(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_unitPrice));
		project.setLandValue(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_landValue));
		project.setBoundary(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_boundary));
		project.setIndustry(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_industry));
		project.setJsnr(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_jsnr));
		project.setBenefit(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_benefit));
		project.setCooperation(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_cooperation));
		project.setBuildYears(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_buildYears));
		project.setCurStatus(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_curStatus));
		project.setGovernment(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_government));
		project.setContacts(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_contacts));
		project.setScfy(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_scfy));
		project.setGcfy(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_gcfy));
		project.setZfsy(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_zfsy));
		project.setTzhbhsy(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_tzhbhsy));
		project.setGcjssy(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_gcjssy));
		project.setJyxsynx(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_jyxsynx));
		project.setTdsctzht(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_tdsctzht));
		project.setCjxmtzxy(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_cjxmtzxy));
		project.setZfcyfs(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_zfcyfs));
		project.setNcydczms(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_ncydczms));
		project.setLocSummary(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_locSummary));
		project.setProject_id(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_project_id));
		project.setPt_pic(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_pt_pic));
		project.setSchool(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_school));
		project.setHospital(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_hospital));
		project.setBusiness(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_business));
		project.setPark(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_park));
		project.setSzpt(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_szpt));
		project.setFinance(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_finance));
		project.setEarnings(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_earnings));
		project.setGdjh(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_gdjh));
		project.setIsRecom(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_isRecom));
		project.setPppType(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_pppType));
		project.setAssetIdxTxt(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_assetIdxTxt));
		project.setSzb(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_szb));
		project.setOtherCon(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_otherCon));
		project.setLocation_pic(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_location_pic));
		project.setSource(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_source));
		project.setSite(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_site));
		project.setUrl(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_url));
		project.setProcess(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_process));
		project.setSummary(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_summary));
		project.setProvince(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_province));
		project.setCounty(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_county));
		project.setTraffic(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_traffic));
		project.setZbdj(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_zbdj));
		project.setZbfj(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_zbfj));
		project.setZrdp(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_zrdp));
		project.setGcjs(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_gcjs));
		project.setShortName(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_shortName));
		project.setUserID(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_userID));
		project.setUserName(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_userName));
		project.setGdsj(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_gdsj));
		project.setPtPicPc(this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_ptPicPc));
		
		return project;
	}
	
	/**
	 * 查询指定列内容
	 * @param provincePostcode
	 * @param cityPostcode
	 * @param countyPostcode
	 * @param projectID
	 * @param qualifierList 列名list，列名要在HbaseTableProjectInfo定义列名范围内
	 * @return Map<列名, 列内容>
	 */
	public Map<String, String> getSpecialItem(String provincePostcode, String cityPostcode, String countyPostcode, int projectID, List<String> qualifierList){
		if(qualifierList == null || qualifierList.size() == 0){
			return null;
		}
		Map<String, String> map = new HashMap<String, String>();
		Table table = null;
		Connection conn = null;
		try {
			conn = this.initConn();
			table = conn.getTable(this.tableNameMap
					.get(HbaseTableProjectInfo.TABLE_NAME));
			if(cityPostcode == null || cityPostcode.length() == 0){
				cityPostcode = "0";
			}
			if(countyPostcode == null || countyPostcode.length() == 0){
				countyPostcode = "0";
			}
			String rowKey = provincePostcode + "_" + cityPostcode + "_" + countyPostcode + "_" + projectID;
			Get get = new Get(Bytes.toBytes(rowKey));
			Result result = table.get(get);
			if (result != null) {
				for(String qualifier: qualifierList){
					String value = this.getRow(result, HbaseTableProjectInfo.COLUMN_FAMILY, HbaseTableProjectInfo.Column_Name_location_pic);
					map.put(qualifier, value);
				}
			}
			this.retryTimes = 0;
		} catch (Exception e) {
			this.logger.error("Exception! key: " + provincePostcode + "_" + cityPostcode + "_" + countyPostcode + "_" + projectID, e);
			if(++this.retryTimes <= 5){
				try {
					Thread.sleep(2000);
				} catch (Exception e1) {}
				map = this.getSpecialItem(provincePostcode, cityPostcode, countyPostcode, projectID, qualifierList);						
			}
		} finally {
			this.closeConn(table, conn);
		}
		
		return map;
	}
	
	/**
	 * 查询项目优势
	 * @param provincePostcode
	 * @param cityPostcode
	 * @param countyPostcode
	 * @param projectID
	 * @return
	 */
	public HBProjectAdvantage getProjectAdvantage(String provincePostcode, String cityPostcode, String countyPostcode, int projectID){
		Table table = null;
		HBProjectAdvantage pa = null;
		Connection conn = null;
		try {
			conn = this.initConn();
			table = conn.getTable(this.tableNameMap.get(HbaseTableProjectAdvantage.TABLE_NAME));
			if(cityPostcode == null || cityPostcode.length() == 0){
				cityPostcode = "0";
			}
			if(countyPostcode == null || countyPostcode.length() == 0){
				countyPostcode = "0";
			}
			String rowKey = provincePostcode + "_" + cityPostcode + "_" + countyPostcode + "_" + projectID + "_adv";
			Get get = new Get(Bytes.toBytes(rowKey));
			Result result = table.get(get);
			if (result != null) {
				pa = new HBProjectAdvantage();
				pa.setProjectID(projectID);
				pa.setProvincePostcode(provincePostcode);
				pa.setCityPostcode(cityPostcode);
				pa.setCountyPostcode(countyPostcode);
				pa.setLocation(this.getRow(result, HbaseTableProjectAdvantage.COLUMN_FAMILY, HbaseTableProjectAdvantage.Column_Name_location));
				pa.setTraffic(this.getRow(result, HbaseTableProjectAdvantage.COLUMN_FAMILY, HbaseTableProjectAdvantage.Column_Name_traffic));
				pa.setSupFacilities(this.getRow(result, HbaseTableProjectAdvantage.COLUMN_FAMILY, HbaseTableProjectAdvantage.Column_Name_supFacilities));
				pa.setOther(this.getRow(result, HbaseTableProjectAdvantage.COLUMN_FAMILY, HbaseTableProjectAdvantage.Column_Name_other));
			}
			this.retryTimes = 0;
		} catch (Exception e) {
			this.logger.error("Exception! key: " + provincePostcode + "_" + cityPostcode + "_" + countyPostcode + "_" + projectID, e);
			if(++this.retryTimes <= 5){
				try {
					Thread.sleep(2000);
				} catch (Exception e1) {}
				pa = this.getProjectAdvantage(provincePostcode, cityPostcode, countyPostcode, projectID);						
			}
		} finally {
			this.closeConn(table, conn);
		}
		return pa;
	}
	
	/**
	 * 项目经济分析
	 * @param provincePostcode
	 * @param cityPostcode
	 * @param countyPostcode
	 * @param projectID
	 * @return
	 */
	public HBProjectEconomic getProjectEconomic(String provincePostcode, String cityPostcode, String countyPostcode, int projectID){
		Table table = null;
		HBProjectEconomic pe = null;
		Connection conn = null;
		try {
			conn = this.initConn();
			table = conn.getTable(this.tableNameMap.get(HbaseTableProjectEconomic.TABLE_NAME));
			if(cityPostcode == null || cityPostcode.length() == 0){
				cityPostcode = "0";
			}
			if(countyPostcode == null || countyPostcode.length() == 0){
				countyPostcode = "0";
			}
			String rowKey = provincePostcode + "_" + cityPostcode + "_" + countyPostcode + "_" + projectID + "_eco";
			Get get = new Get(Bytes.toBytes(rowKey));
			Result result = table.get(get);
			if (result != null) {
				pe = new HBProjectEconomic();
				pe.setProjectID(projectID);
				pe.setProjectID(projectID);
				pe.setProvincePostcode(provincePostcode);
				pe.setCityPostcode(cityPostcode);
				pe.setCountyPostcode(countyPostcode);
				pe.setDktzkfzcb(this.getRow(result, HbaseTableProjectEconomic.COLUMN_FAMILY, HbaseTableProjectEconomic.Column_Name_dktzkfzcb));
				pe.setDkxssrcsb(this.getRow(result, HbaseTableProjectEconomic.COLUMN_FAMILY, HbaseTableProjectEconomic.Column_Name_dkxssrcsb));
				pe.setXmjjxycsb(this.getRow(result, HbaseTableProjectEconomic.COLUMN_FAMILY, HbaseTableProjectEconomic.Column_Name_xmjjxycsb));
				pe.setTdjgtsb(this.getRow(result, HbaseTableProjectEconomic.COLUMN_FAMILY, HbaseTableProjectEconomic.Column_Name_tdjgtsb));
			}
			this.retryTimes = 0;
		} catch (Exception e) {
			this.logger.error("Exception! key: " + provincePostcode + "_" + cityPostcode + "_" + countyPostcode + "_" + projectID, e);
			if(++this.retryTimes <= 5){
				try {
					Thread.sleep(2000);
				} catch (Exception e1) {}
				pe = this.getProjectEconomic(provincePostcode, cityPostcode, countyPostcode, projectID);						
			}
		} finally {
			this.closeConn(table, conn);
		}
		return pe;
	}
	
	/**
	 * 项目市场分析
	 * @param provincePostcode
	 * @param cityPostcode
	 * @param countyPostcode
	 * @param projectID
	 * @return
	 */
	public HBProjectMarket getProjectMarket(String provincePostcode, String cityPostcode, String countyPostcode, int projectID){
		Table table = null;
		HBProjectMarket pm = null;
		Connection conn = null;
		try {
			conn = this.initConn();
			table = conn.getTable(this.tableNameMap.get(HbaseTableProjectMarket.TABLE_NAME));
			if(cityPostcode == null || cityPostcode.length() == 0){
				cityPostcode = "0";
			}
			if(countyPostcode == null || countyPostcode.length() == 0){
				countyPostcode = "0";
			}
			String rowKey = provincePostcode + "_" + cityPostcode + "_" + countyPostcode + "_" + projectID + "_mar";
			Get get = new Get(Bytes.toBytes(rowKey));
			Result result = table.get(get);
			if (result != null) {
				pm = new HBProjectMarket();
				pm.setProjectID(projectID);
				pm.setProvincePostcode(provincePostcode);
				pm.setCityPostcode(cityPostcode);
				pm.setCountyPostcode(countyPostcode);
				pm.setInvestEnv(this.getRow(result, HbaseTableProjectMarket.COLUMN_FAMILY, HbaseTableProjectMarket.Column_Name_investEnv));
				pm.setInvestEnvIMG(this.getRow(result, HbaseTableProjectMarket.COLUMN_FAMILY, HbaseTableProjectMarket.Column_Name_investEnvIMG));
				pm.setRealEMarket(this.getRow(result, HbaseTableProjectMarket.COLUMN_FAMILY, HbaseTableProjectMarket.Column_Name_realEMarket));
				pm.setRealEMarketIMG(this.getRow(result, HbaseTableProjectMarket.COLUMN_FAMILY, HbaseTableProjectMarket.Column_Name_realEMarketIMG));
				pm.setLandLeasing(this.getRow(result, HbaseTableProjectMarket.COLUMN_FAMILY, HbaseTableProjectMarket.Column_Name_landLeasing));
				pm.setLandLeasingIMG(this.getRow(result, HbaseTableProjectMarket.COLUMN_FAMILY, HbaseTableProjectMarket.Column_Name_landLeasingIMG));
			}
			this.retryTimes = 0;
		} catch (Exception e) {
			this.logger.error("Exception! key: " + provincePostcode + "_" + cityPostcode + "_" + countyPostcode + "_" + projectID, e);
			if(++this.retryTimes <= 5){
				try {
					Thread.sleep(2000);
				} catch (Exception e1) {}
				pm = this.getProjectMarket(provincePostcode, cityPostcode, countyPostcode, projectID);						
			}
		} finally {
			this.closeConn(table, conn);
		}
		return pm;
	}
	
	/**
	 * 查询项目附件
	 * @param provincePostcode
	 * @param cityPostcode
	 * @param countyPostcode
	 * @param projectID
	 * @return
	 */
	public List<HBProjectAttachment> getProjectAttach(String provincePostcode, String cityPostcode, String countyPostcode, int projectID){
		List<HBProjectAttachment> attList = new ArrayList<HBProjectAttachment>();
		Table table = null;
		ResultScanner rs = null;
		Connection conn = null;		
		try {
			if(cityPostcode == null || cityPostcode.length() == 0){
				cityPostcode = "0";
			}
			if(countyPostcode == null || countyPostcode.length() == 0){
				countyPostcode = "0";
			}
			conn = this.initConn();
			table = conn.getTable(this.tableNameMap.get(HbaseTableProjectAttachment.TABLE_NAME));
			String startRow = provincePostcode + "_" + cityPostcode + "_" + countyPostcode + "_" + projectID + "_att_0";
			String stopRow = provincePostcode + "_" + cityPostcode + "_" + countyPostcode + "_" + projectID + "_att_9";
			Scan scan = new Scan(Bytes.toBytes(startRow), Bytes.toBytes(stopRow));
			rs = table.getScanner(scan);
			for(Result result: rs.next(100)){
				HBProjectAttachment att = this.getAttachEntity(result);
				att.setProjectID(projectID);
				att.setProvincePostcode(provincePostcode);
				att.setCityPostcode(cityPostcode);
				att.setCountyPostcode(countyPostcode);
				attList.add(att);
			}
			this.retryTimes = 0;
		} catch (Exception e) {
			this.logger.error("Exception! key: " + provincePostcode + "_" + cityPostcode + "_" + countyPostcode + "_" + projectID, e);
			if(++this.retryTimes <= 5){
				try {
					Thread.sleep(2000);
				} catch (Exception e1) {}
				attList = this.getProjectAttach(provincePostcode, cityPostcode, countyPostcode, projectID);						
			}
		} finally{
			this.closeConn(table, conn);
		}
		return attList;
	}
	
	/**
	 * 查询项目附件
	 * @param provincePostcode
	 * @param cityPostcode
	 * @param countyPostcode
	 * @param projectID
	 * @return
	 */
	public HBProjectAttachment getProjectAttach(String rowKey){
		HBProjectAttachment att = null;
		Table table = null;
		Connection conn = null;
		try {
			conn = this.initConn();
			table = conn.getTable(this.tableNameMap.get(HbaseTableProjectAttachment.TABLE_NAME));
			Get get = new Get(Bytes.toBytes(rowKey));
			Result result = table.get(get);
			if(result != null){
				att = this.getAttachEntity(result);
				String[] ary = rowKey.split("_");
				att.setProvincePostcode(ary[0]);
				att.setCityPostcode(ary[1]);
				att.setCountyPostcode(ary[2]);
				att.setProjectID(Integer.parseInt(ary[3]));
			}
			this.retryTimes = 0;
		} catch (Exception e) {
			this.logger.error("Exception! key: " + rowKey, e);
			if(++this.retryTimes <= 5){
				try {
					Thread.sleep(2000);
				} catch (Exception e1) {}
				att = this.getProjectAttach(rowKey);
			}
		} finally{
			this.closeConn(table, conn);
		}
		return att;
	}
	
	/**
	 * 将查询结果封装
	 * @param result
	 * @return
	 */
	private HBProjectAttachment getAttachEntity(Result result){
		HBProjectAttachment att = new HBProjectAttachment();
		for (Cell cell : result.rawCells()) {
			String quilifier = Bytes.toString(CellUtil.cloneQualifier(cell));
			String value = Bytes.toString(CellUtil.cloneValue(cell));
			//只有一个family，因此不做family的判断
			if(quilifier.equals(HbaseTableProjectAttachment.Column_Name_genus)){att.setGenus(value);}
			else if(quilifier.equals(HbaseTableProjectAttachment.Column_Name_name)){att.setName(value);}
			else if(quilifier.equals(HbaseTableProjectAttachment.Column_Name_type)){att.setType(value);}
			else if(quilifier.equals(HbaseTableProjectAttachment.Column_Name_path)){att.setPath(value);}
			else if(quilifier.equals(HbaseTableProjectAttachment.Column_Name_submitTime)){att.setSubmitTime(value);}
			else if(quilifier.equals(HbaseTableProjectAttachment.Column_Name_summary)){att.setSummary(value);}
			else if(quilifier.equals(HbaseTableProjectAttachment.Column_Name_person)){att.setPerson(value);}
			else if(quilifier.equals(HbaseTableProjectAttachment.Column_Name_publishDep)){att.setPublishDep(value);}
			else if(quilifier.equals(HbaseTableProjectAttachment.Column_Name_publishDate)){att.setPublishDate(value);}
			else {
				this.logger.warn("unknown quilifier! quilifier: " + quilifier);;
			}
		}
		return att;
	}
	
	/**
	 * 查询项目图片、视频信息
	 * @param provincePostcode
	 * @param cityPostcode
	 * @param countyPostcode
	 * @param projectID
	 * @return
	 */
	public List<HBProjectMedia> getProjectMedia(String provincePostcode, String cityPostcode, String countyPostcode, int projectID){
		List<HBProjectMedia> mediaList = new ArrayList<HBProjectMedia>();
		Table table = null;
		ResultScanner rs = null;
		Connection conn = null;
		
		try {
			if(cityPostcode == null || cityPostcode.length() == 0){
				cityPostcode = "0";
			}
			if(countyPostcode == null || countyPostcode.length() == 0){
				countyPostcode = "0";
			}
			conn = this.initConn();
			table = conn.getTable(this.tableNameMap.get(HbaseTableProjectMedia.TABLE_NAME));
			String startRow = provincePostcode + "_" + cityPostcode + "_" + countyPostcode + "_" + projectID + "_med_0";
			String stopRow = provincePostcode + "_" + cityPostcode + "_" + countyPostcode + "_" + projectID + "_med_9";
			Scan scan = new Scan(Bytes.toBytes(startRow), Bytes.toBytes(stopRow));
			rs = table.getScanner(scan);
			for(Result result: rs.next(100)){
				HBProjectMedia media = this.getMdeiaEntity(result);
				media.setProjectID(projectID);
				media.setProvincePostcode(provincePostcode);
				media.setCityPostcode(cityPostcode);
				media.setCountyPostcode(countyPostcode);
				mediaList.add(media);
			}
			this.retryTimes = 0;
		} catch (Exception e) {
			this.logger.error("Exception! key: " + provincePostcode + "_" + cityPostcode + "_" + countyPostcode + "_" + projectID, e);
			if(++this.retryTimes <= 5){
				try {
					Thread.sleep(2000);
				} catch (Exception e1) {}
				mediaList = this.getProjectMedia(provincePostcode, cityPostcode, countyPostcode, projectID);						
			}
		} finally{
			this.closeConn(table, conn);
		}
		return mediaList;
	}
	
	/**
	 * 查询指定类型多媒体信息
	 * @param provincePostcode
	 * @param cityPostcode
	 * @param countyPostcode
	 * @param projectID
	 * @param mediaType 1：图片，2：视频，3：音频
	 * @return
	 */
	public List<HBProjectMedia> getProjectMedia(String provincePostcode, String cityPostcode, String countyPostcode, int projectID, int mediaType){
		List<HBProjectMedia> mediaList = new ArrayList<HBProjectMedia>();
		Table table = null;
		ResultScanner rs = null;
		Connection conn = null;
		
		try {
			if(cityPostcode == null || cityPostcode.length() == 0){
				cityPostcode = "0";
			}
			if(countyPostcode == null || countyPostcode.length() == 0){
				countyPostcode = "0";
			}
			conn = this.initConn();
			table = conn.getTable(this.tableNameMap.get(HbaseTableProjectMedia.TABLE_NAME));
			String startRow = provincePostcode + "_" + cityPostcode + "_" + countyPostcode + "_" + projectID + "_med_" + mediaType + "_0";
			String stopRow = provincePostcode + "_" + cityPostcode + "_" + countyPostcode + "_" + projectID + "_med_" + mediaType + "_z";
			Scan scan = new Scan(Bytes.toBytes(startRow), Bytes.toBytes(stopRow));
			rs = table.getScanner(scan);
			for(Result result: rs.next(100)){
				HBProjectMedia media = this.getMdeiaEntity(result);
				media.setProjectID(projectID);
				media.setProvincePostcode(provincePostcode);
				media.setCityPostcode(cityPostcode);
				media.setCountyPostcode(countyPostcode);
				mediaList.add(media);
			}
			this.retryTimes = 0;
		} catch (Exception e) {
			this.logger.error("Exception! key: " + provincePostcode + "_" + cityPostcode + "_" + countyPostcode + "_" + projectID, e);
			if(++this.retryTimes <= 5){
				try {
					Thread.sleep(2000);
				} catch (Exception e1) {}
				mediaList = this.getProjectMedia(provincePostcode, cityPostcode, countyPostcode, projectID);						
			}
		} finally{
			this.closeConn(table, conn);
		}
		return mediaList;
	}
	
	/**
	 * 查询项目图片、视频信息
	 * @param provincePostcode
	 * @param cityPostcode
	 * @param countyPostcode
	 * @param projectID
	 * @return
	 */
	public HBProjectMedia getProjectMedia(String rowKey){
		HBProjectMedia media = null;
		Table table = null;
		Connection conn = null;
		
		try {
			conn = this.initConn();
			table = conn.getTable(this.tableNameMap.get(HbaseTableProjectMedia.TABLE_NAME));
			Get get = new Get(Bytes.toBytes(rowKey));
			Result result = table.get(get);
			if(result != null){
				media = this.getMdeiaEntity(result);
				String[] ary = rowKey.split("_");
				media.setProvincePostcode(ary[0]);
				media.setCityPostcode(ary[1]);
				media.setCountyPostcode(ary[2]);
				media.setProjectID(Integer.parseInt(ary[3]));
			}
			this.retryTimes = 0;
		} catch (Exception e) {
			this.logger.error("Exception! key: " + rowKey, e);
			if(++this.retryTimes <= 5){
				try {
					Thread.sleep(2000);
				} catch (Exception e1) {}
				media = this.getProjectMedia(rowKey);						
			}
		} finally{
			this.closeConn(table, conn);
		}
		return media;
	}
	
	/**
	 * 将查询结果封装
	 * @param result
	 * @return
	 */
	private HBProjectMedia getMdeiaEntity(Result result){
		HBProjectMedia media = new HBProjectMedia();
		for (Cell cell : result.rawCells()) {
			String quilifier = Bytes.toString(CellUtil.cloneQualifier(cell));
			String value = Bytes.toString(CellUtil.cloneValue(cell));
			//只有一个family，因此不做family的判断
			if(quilifier.equals(HbaseTableProjectMedia.Column_Name_type)){media.setType(value);}
			else if(quilifier.equals(HbaseTableProjectMedia.Column_Name_name)){media.setName(value);}
			else if(quilifier.equals(HbaseTableProjectMedia.Column_Name_path)){media.setPath(value);}
			else if(quilifier.equals(HbaseTableProjectMedia.Column_Name_summary)){media.setSummary(value);}
			else if(quilifier.equals(HbaseTableProjectMedia.Column_Name_person)){media.setPerson(value);}
			else if(quilifier.equals(HbaseTableProjectMedia.Column_Name_submitTime)){media.setSubmitTime(value);}
			else if(quilifier.equals(HbaseTableProjectMedia.Column_Name_publishDep)){media.setPublishDep(value);}
			else if(quilifier.equals(HbaseTableProjectMedia.Column_Name_publishDate)){media.setPublishDate(value);}
			else {
				this.logger.warn("unknown quilifier! quilifier: " + quilifier);;
			}
		}
		return media;
	}
	
	/**
	 * 插入项目信息
	 * @param project
	 * @return status
	 */
	public HbaseStatus insertProject(HBProjectInfo project){
		HbaseStatus status = HbaseStatus.successed;
		Table table = null;
		Connection conn = null;
		if(project.getProvincePostcode() == null || project.getProvincePostcode().length() == 0 || project.getMysqlID() <= 0){
			return HbaseStatus.illogic;
		}
		try {
			if(project.getCityPostcode() == null || project.getCityPostcode().length() == 0){
				project.setCityPostcode("0");
			}
			if(project.getCountyPostcode() == null || project.getCountyPostcode().length() == 0){
				project.setCountyPostcode("0");
			}
			conn = this.initConn();
			table = conn.getTable(this.tableNameMap.get(HbaseTableProjectInfo.TABLE_NAME));
			String rowKey = project.getProvincePostcode() + "_" + project.getCityPostcode() + "_" + project.getCountyPostcode() + "_" + project.getMysqlID();
			Put put = new Put(Bytes.toBytes(rowKey));
			byte[] famByt = Bytes.toBytes(HbaseTableProjectInfo.COLUMN_FAMILY);
			
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_type, project.getType());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_name, project.getName());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_isCase, project.getIsCase());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_city, project.getCity());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_cityKey, project.getCityKey());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_hotValue, project.getHotValue());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_isValidate, project.getIsValidate());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_status, project.getStatus());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_intro, project.getIntro());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_investment, project.getInvestment());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_trade, project.getTrade());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_deposit, project.getDeposit());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_reserve, project.getReserve());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_payment, project.getPayment());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_tradeDate, project.getTradeDate());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_location, project.getLocation());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_geoCoor, project.getGeoCoor());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_restricted, project.getRestricted());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_policy, project.getPolicy());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_keywords, project.getKeywords());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_background, project.getBackground());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_assetType, project.getAssetType());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_assetIndex, project.getAssetIndex());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_purpose, project.getPurpose());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_plotRatio, project.getPlotRatio());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_ywhjf, project.getYwhjf());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_builDensity, project.getBuilDensity());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_greeningRate, project.getGreeningRate());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_maxHeight, project.getMaxHeight());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_area, project.getArea());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_unitPrice, project.getUnitPrice());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_landValue, project.getLandValue());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_boundary, project.getBoundary());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_industry, project.getIndustry());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_jsnr, project.getJsnr());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_benefit, project.getBenefit());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_cooperation, project.getCooperation());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_buildYears, project.getBuildYears());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_curStatus, project.getCurStatus());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_government, project.getGovernment());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_contacts, project.getContacts());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_scfy, project.getScfy());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_gcfy, project.getGcfy());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_zfsy, project.getZfsy());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_tzhbhsy, project.getTzhbhsy());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_gcjssy, project.getGcjssy());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_jyxsynx, project.getJyxsynx());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_tdsctzht, project.getTdsctzht());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_cjxmtzxy, project.getCjxmtzxy());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_zfcyfs, project.getZfcyfs());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_ncydczms, project.getNcydczms());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_locSummary, project.getLocSummary());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_project_id, project.getProject_id());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_pt_pic, project.getPt_pic());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_school, project.getSchool());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_hospital, project.getHospital());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_business, project.getBusiness());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_park, project.getPark());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_szpt, project.getSzpt());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_finance, project.getFinance());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_earnings, project.getEarnings());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_gdjh, project.getGdjh());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_isRecom, project.getIsRecom());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_pppType, project.getPppType());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_assetIdxTxt, project.getAssetIdxTxt());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_szb, project.getSzb());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_otherCon, project.getOtherCon());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_location_pic, project.getLocation_pic());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_site, project.getSite());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_url, project.getUrl());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_source, project.getSource());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_process, project.getProcess());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_summary, project.getSummary());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_province, project.getProvince());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_county, project.getCounty());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_traffic, project.getTraffic());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_zbdj, project.getZbdj());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_zbfj, project.getZbfj());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_zrdp, project.getZrdp());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_gcjs, project.getGcjs());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_shortName, project.getShortName());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_userID, project.getUserID());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_userName, project.getUserName());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_gdsj, project.getGdsj());
			this.addValue(put, famByt, HbaseTableProjectInfo.Column_Name_ptPicPc, project.getPtPicPc());
			
			table.put(put);
			if(project.getAdvantage()!= null){
				this.insertProjectAdvantage(project.getAdvantage());
			}
			if(project.getAttList()!= null && project.getAttList().size() > 0){
				this.insertProjectAttach(project.getAttList());
			}
			if(project.getEconomic()!= null){
				this.insertProjectEconomic(project.getEconomic());
			}
			if(project.getMarket()!= null){
				this.insertProjectMarket(project.getMarket());
			}
			if(project.getMediaList()!= null && project.getMediaList().size() > 0){
				this.insertProjectMedia(project.getMediaList());
			}
			this.retryTimes = 0;
		} catch (Exception e) {
			this.logger.error("Exception!", e);
			if(++this.retryTimes <= 5){
				try {
					Thread.sleep(2000);
				} catch (Exception e1) {}
				status = this.insertProject(project);
			} else{
				status = HbaseStatus.exception;
			}
		} finally{
			this.closeConn(table, conn);
		}
		return status;
	}
	
	/**
	 * 批量提交项目附件
	 * @param attachList
	 * @return status
	 */
	public HbaseStatus insertProjectAttach(List<HBProjectAttachment> attachList){
		HbaseStatus status = HbaseStatus.successed;
		Table table = null;
		Connection conn = null;
		try {
			conn = this.initConn();
			table = conn.getTable(this.tableNameMap.get(HbaseTableProjectAttachment.TABLE_NAME));
			for(HBProjectAttachment att: attachList){
				if(att.getProvincePostcode() == null || att.getProvincePostcode().length() == 0 || att.getType() == null || att.getType().length() == 0 || att.getProjectID() <= 0){
					this.logger.warn("illogial data!");
					status = HbaseStatus.illogic;
					continue;
				}
				if(att.getCityPostcode() == null || att.getCityPostcode().length() == 0){
					att.setCityPostcode("0");
				}
				if(att.getCountyPostcode() == null || att.getCountyPostcode().length() == 0){
					att.setCountyPostcode("0");
				}
				String rowKey = att.getProvincePostcode() + "_" + att.getCityPostcode() + "_" + att.getCountyPostcode() + "_" + att.getProjectID() + "_att_" + att.getType();
				Put put = new Put(Bytes.toBytes(rowKey));
				byte[] famByt = Bytes.toBytes(HbaseTableProjectAttachment.COLUMN_FAMILY);
				
				this.addValue(put, famByt, HbaseTableProjectAttachment.Column_Name_genus, att.getGenus());
				this.addValue(put, famByt, HbaseTableProjectAttachment.Column_Name_name, att.getName());
				this.addValue(put, famByt, HbaseTableProjectAttachment.Column_Name_type, att.getType());
				this.addValue(put, famByt, HbaseTableProjectAttachment.Column_Name_path, att.getPath());
				this.addValue(put, famByt, HbaseTableProjectAttachment.Column_Name_submitTime, att.getSubmitTime());
				this.addValue(put, famByt, HbaseTableProjectAttachment.Column_Name_summary, att.getSummary());
				this.addValue(put, famByt, HbaseTableProjectAttachment.Column_Name_person, att.getPerson());
				this.addValue(put, famByt, HbaseTableProjectAttachment.Column_Name_publishDep, att.getPublishDep());
				this.addValue(put, famByt, HbaseTableProjectAttachment.Column_Name_publishDate, att.getPublishDate());
				table.put(put);
			}
		} catch (Exception e) {
			e.printStackTrace();
			status = HbaseStatus.exception;
		} finally{
			this.closeConn(table, conn);
		}
		return status;
	}
	
	/**
	 * 批量提交项目图片、视频
	 * @param mediaList
	 * @return status
	 */
	public HbaseStatus insertProjectMedia(List<HBProjectMedia> mediaList){
		HbaseStatus status = HbaseStatus.successed;
		Table table = null;
		Connection conn = null;
		try {
			conn = this.initConn();
			table = conn.getTable(this.tableNameMap.get(HbaseTableProjectMedia.TABLE_NAME));
			for(HBProjectMedia media: mediaList){
				if(media.getProvincePostcode() == null || media.getProvincePostcode().length() == 0 || media.getName() == null || media.getName().length() == 0 || media.getProjectID() <= 0){
					this.logger.warn("illogial data!");
					continue;
				}
				if(media.getCityPostcode() == null || media.getCityPostcode().length() == 0){
					media.setCityPostcode("0");
				}
				if(media.getCountyPostcode() == null || media.getCountyPostcode().length() == 0){
					media.setCountyPostcode("0");
				}
				String rowKey = media.getProvincePostcode() + "_" + media.getCityPostcode() + "_" + media.getCountyPostcode() + "_" + media.getProjectID() + "_med_" + media.getType() + "_" + MD5Util.createMd5(media.getName());
				Put put = new Put(Bytes.toBytes(rowKey));
				byte[] famByt = Bytes.toBytes(HbaseTableProjectMedia.COLUMN_FAMILY);
				
				this.addValue(put, famByt, HbaseTableProjectMedia.Column_Name_type, media.getType());
				this.addValue(put, famByt, HbaseTableProjectMedia.Column_Name_name, media.getName());
				this.addValue(put, famByt, HbaseTableProjectMedia.Column_Name_path, media.getPath());
				this.addValue(put, famByt, HbaseTableProjectMedia.Column_Name_summary, media.getSummary());
				this.addValue(put, famByt, HbaseTableProjectMedia.Column_Name_person, media.getPerson());
				this.addValue(put, famByt, HbaseTableProjectMedia.Column_Name_submitTime, media.getSubmitTime());
				this.addValue(put, famByt, HbaseTableProjectMedia.Column_Name_publishDep, media.getPublishDep());
				this.addValue(put, famByt, HbaseTableProjectMedia.Column_Name_publishDate, media.getPublishDate());
				table.put(put);
			}
		} catch (Exception e) {
			e.printStackTrace();
			status = HbaseStatus.exception;
		} finally{
			this.closeConn(table, conn);
		}
		return status;
	}
	
	/**
	 * 提交项目优势分析信息
	 * @param advant
	 * @return status
	 */
	public HbaseStatus insertProjectAdvantage(HBProjectAdvantage advant){
		HbaseStatus status = HbaseStatus.successed;
		Table table = null;
		if(advant.getProvincePostcode() == null || advant.getProvincePostcode().length() == 0 || advant.getProjectID() <= 0){
			return HbaseStatus.illogic;
		}
		Connection conn = null;
		try {
			if(advant.getCityPostcode() == null || advant.getCityPostcode().length() == 0){
				advant.setCityPostcode("0");
			}
			if(advant.getCountyPostcode() == null || advant.getCountyPostcode().length() == 0){
				advant.setCountyPostcode("0");
			}
			conn = this.initConn();
			table = conn.getTable(this.tableNameMap.get(HbaseTableProjectAdvantage.TABLE_NAME));
			String rowKey = advant.getProvincePostcode() + "_" + advant.getCityPostcode() + "_" + advant.getCountyPostcode() + "_" + advant.getProjectID() + "_adv";
			Put put = new Put(Bytes.toBytes(rowKey));
			byte[] famByt = Bytes.toBytes(HbaseTableProjectAdvantage.COLUMN_FAMILY);
			
			this.addValue(put, famByt, HbaseTableProjectAdvantage.Column_Name_location, advant.getLocation());
			this.addValue(put, famByt, HbaseTableProjectAdvantage.Column_Name_traffic, advant.getTraffic());
			this.addValue(put, famByt, HbaseTableProjectAdvantage.Column_Name_supFacilities, advant.getSupFacilities());
			this.addValue(put, famByt, HbaseTableProjectAdvantage.Column_Name_other, advant.getOther());
			table.put(put);
		} catch (Exception e) {
			e.printStackTrace();
			status = HbaseStatus.exception;
		} finally{
			this.closeConn(table, conn);
		}
		return status;
	}
	
	/**
	 * 提交项目经济分析信息
	 * @param economic
	 * @return status
	 */
	public HbaseStatus insertProjectEconomic(HBProjectEconomic economic){
		HbaseStatus status = HbaseStatus.successed;
		Table table = null;
		Connection conn = null;
		if(economic.getProvincePostcode() == null || economic.getProvincePostcode().length() == 0 || economic.getProjectID() <= 0){
			return HbaseStatus.illogic;
		}
		try {
			if(economic.getCityPostcode() == null || economic.getCityPostcode().length() == 0){
				economic.setCityPostcode("0");
			}
			if(economic.getCountyPostcode() == null || economic.getCountyPostcode().length() == 0){
				economic.setCountyPostcode("0");
			}
			conn = this.initConn();
			table = conn.getTable(this.tableNameMap.get(HbaseTableProjectEconomic.TABLE_NAME));
			String rowKey = economic.getProvincePostcode() + "_" + economic.getCityPostcode() + "_" + economic.getCountyPostcode() + "_" + economic.getProjectID() + "_eco";
			Put put = new Put(Bytes.toBytes(rowKey));
			byte[] famByt = Bytes.toBytes(HbaseTableProjectEconomic.COLUMN_FAMILY);
			this.addValue(put, famByt, HbaseTableProjectEconomic.Column_Name_dktzkfzcb, economic.getDktzkfzcb());
			this.addValue(put, famByt, HbaseTableProjectEconomic.Column_Name_dkxssrcsb, economic.getDkxssrcsb());
			this.addValue(put, famByt, HbaseTableProjectEconomic.Column_Name_xmjjxycsb, economic.getXmjjxycsb());
			this.addValue(put, famByt, HbaseTableProjectEconomic.Column_Name_tdjgtsb, economic.getTdjgtsb());
			table.put(put);
		} catch (Exception e) {
			e.printStackTrace();
			status = HbaseStatus.exception;
		} finally{
			this.closeConn(table, conn);
		}
		return status;
	}
	
	/**
	 * 提交项目市场分析信息
	 * @param market
	 * @return status
	 */
	public HbaseStatus insertProjectMarket(HBProjectMarket market){
		HbaseStatus status = HbaseStatus.successed;
		Table table = null;
		Connection conn = null;
		if(market.getProvincePostcode() == null || market.getProvincePostcode().length() == 0 || market.getProjectID() <= 0){
			return HbaseStatus.illogic;
		}
		try {
			if(market.getCityPostcode() == null || market.getCityPostcode().length() == 0){
				market.setCityPostcode("0");
			}
			if(market.getCountyPostcode() == null || market.getCountyPostcode().length() == 0){
				market.setCountyPostcode("0");
			}
			conn = this.initConn();
			table = conn.getTable(this.tableNameMap.get(HbaseTableProjectMarket.TABLE_NAME));
			String rowKey = market.getProvincePostcode() + "_" + market.getCityPostcode() + "_" + market.getCountyPostcode() + "_" + market.getProjectID() + "_mar";
			Put put = new Put(Bytes.toBytes(rowKey));
			byte[] famByt = Bytes.toBytes(HbaseTableProjectMarket.COLUMN_FAMILY);
			this.addValue(put, famByt, HbaseTableProjectMarket.Column_Name_investEnv, market.getInvestEnv());
			this.addValue(put, famByt, HbaseTableProjectMarket.Column_Name_investEnvIMG, market.getInvestEnvIMG());
			this.addValue(put, famByt, HbaseTableProjectMarket.Column_Name_realEMarket, market.getRealEMarket());
			this.addValue(put, famByt, HbaseTableProjectMarket.Column_Name_realEMarketIMG, market.getRealEMarketIMG());
			this.addValue(put, famByt, HbaseTableProjectMarket.Column_Name_landLeasing, market.getLandLeasing());
			this.addValue(put, famByt, HbaseTableProjectMarket.Column_Name_landLeasingIMG, market.getLandLeasingIMG());
			table.put(put);
		} catch (Exception e) {
			e.printStackTrace();
			status = HbaseStatus.exception;
		} finally{
			this.closeConn(table, conn);
		}
		return status;
	}
	
	/**
	 * 赋值
	 * @param put
	 * @param famByt
	 * @param qualifier
	 * @param value
	 */
	private void addValue(Put put, byte[] famByt, String qualifier, String value){
		if(value != null){
			put.addColumn(famByt, Bytes.toBytes(qualifier), Bytes.toBytes(value));
		}
	}
	
	/**
	 * 获取指定列的值
	 * @param result
	 * @param familly
	 * @param rowName
	 * @return
	 */
	private String getRow(Result result,String familly,String rowName){
		byte[] byts = result.getValue(Bytes.toBytes(familly), Bytes.toBytes(rowName));
		String row = null;
		if (byts != null && byts.length > 0) {
			row = Bytes.toString(byts);
		}
		return row;
	}

	/*protected void close(ResultScanner rs, Table table) {
		try {
			rs.close();
		} catch (Exception e) {e.printStackTrace();}
		try {
			table.close();
		} catch (Exception e1) {e1.printStackTrace();}
	}
	*/
	private void closeConn(Connection conn){
		try {
			conn.close();
		} catch (Exception e) {e.printStackTrace();}
	}
	
	private void closeConn(Table table,Connection conn){
		try {
			table.close();
			conn.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}
